<template>
  <div class="basic-data-table">
    <a-table :bordered="true" rowKey="level" :pagination="false" :columns="basicColumns" :data-source="basicGameData">
    </a-table>
  </div>
</template>

<script>
  export default {
    name: 'BasicDataTable',
    data () {
      return {
        basicColumns: [
          {
            title: '活动编号',
            dataIndex: 'id',
            customRender: (value, row, index) => {
              const obj = {
                children: value,
                attrs: {}
              }
              // 最多三阶 所有合并三行就够了，合并之后下一列隐藏
              if (index === 0) {
                obj.attrs.rowSpan = 3
              }
              if (index > 0) {
                obj.attrs.colSpan = 0
              }
              return obj
            }
          },
          {
            title: '活动名称',
            dataIndex: 'name',
            customRender: (value, row, index) => {
              const obj = {
                children: value,
                attrs: {}
              }
              if (index === 0) {
                obj.attrs.rowSpan = 3
              }
              if (index > 0) {
                obj.attrs.colSpan = 0
              }
              return obj
            }
          },
          {
            title: '裂变阶梯',
            dataIndex: 'level'
          },
          {
            title: '助力人数',
            dataIndex: 'target'
          },
          {
            title: '阶梯达成用户',
            dataIndex: 'finishCount'
          },
          {
            slots: { title: 'shareRate' },
            dataIndex: 'shareRate',
            align: 'center'
          }
        ],
        basicGameData: []
      }
    },
    methods: {
      init (data) {
        this.basicGameData = []
        const total = data.realDTO.totalJoinCount
        const basicList = data.basicList
        basicList.forEach(item => {
          this.basicGameData.push(
            {
              id: data.id,
              name: data.name,
              level: item.level,
              target: item.target,
              finishCount: item.finishCount,
              shareRate: item.finishCount && total ? (this.$Utils.keepN(item.finishCount / total) * 100) + '%' : '0%'
            }
          )
        })
      }
    }
  }
</script>

<style scoped>

</style>
